package com.zzq.tools;

import com.zzq.pojo.TenderInfo;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

@Component
public class HotTenderCalculator {

    // 权重参数配置
    private static final double VIEW_WEIGHT = 0.3;     // 浏览权重
    private static final double BIDDER_WEIGHT = 0.7;   // 投标人数权重
    private static final double TIME_DECAY_FACTOR = 0.95; // 时间衰减因子

    /**
     * 计算招标项目热度分数
     */
    public double calculateHotScore(TenderInfo tender) {
        // 基础热度分 = 各维度分数加权和
        double baseScore =
                tender.getViewCount() * VIEW_WEIGHT +
                        tender.getBidderCount() * BIDDER_WEIGHT;

        // 时间衰减计算 (项目发布时间越久，热度越低)
        long daysSincePublish = ChronoUnit.DAYS.between(tender.getPublishTime(), LocalDateTime.now());
        double timeDecay = Math.pow(TIME_DECAY_FACTOR, daysSincePublish);

        // 最终热度分 = 基础分数 * 时间衰减因子
        return baseScore * timeDecay*10000;
    }
}